package com.authsphere.springboot.starter.plugin;

import com.authsphere.plugin.api.AuthSphereBeforePlugin;
import com.authsphere.security.captcha.CaptchaBeforePlugin;
import com.authsphere.security.captcha.config.CaptchaConfig;
import com.authsphere.security.captcha.service.GraphicalCaptchaService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/27 21:21
 **/
@Configuration
public class CaptchaPluginConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "authsphere.plugin.captcha")
    public CaptchaConfig captchaConfig() {
        return new CaptchaConfig();
    }

    @Bean
    @ConditionalOnBean(GraphicalCaptchaService.class)
    public AuthSphereBeforePlugin captchaBeforePlugin(
            final CaptchaConfig captchaConfig,
            final GraphicalCaptchaService graphicalCaptchaService) {
        return new CaptchaBeforePlugin(captchaConfig, graphicalCaptchaService);
    }
}
